
C*************************************************************************************
C********COMBINAO -> PRESSO EXTERNA LATERAL + COMPRESSO - TUBO - MANUAL************
C*************************************************************************************


FINISH       			!These two commands clear current data

/clear


! Gerar os arquivos do Ansys com a referncia do Arq

Arq = 3 			! Referncia do ensaio
/FILNAME,Arq_%Arq%,ON
/OUTPUT,Tela_Arq_%Arq%,out	! Salvar a tela preta em um arquivo externo


C*************************************************************************************
C******************************PARMETROS DE ENTRADA**********************************
C*************************************************************************************

/prep7   				! Enter the preprocessor


D_i = 15				! Dimetro do tubo

Ro = D_i*0.5				! Raio do tubo

t = Ro/101				! Espessura do tubo

Lo = Ro*0.325				! Comprimento do tubo

ImpG = 0.014				! Imperfeicao geomtrica requerida no perfil

f_y = 42.5				! Tenso de escoamento ao kN/cm

el_size = 0.1				! Discretizao do elemento

E = 21000				! Mdulo de elasticidade do elemento

MODOF = 1				! Modo de flambagem escolhido para realizar a ANLGM

v=0.3					! Coeficiente Poisson    

FPEL = 0.6				! Fator de carga da PEL variando de 0 a 1

PPU = 0.3657693315			! PEL ltima da ANLGM ou MRD

PCF = 433.8733060396			! Carga crtica de flambagem elstica sobre compresso axial

PCU = 140.1830555986			! PC ltima da ANLGM ou MRD


C*************************************************************************************
C***********************************CARREGAMENTOS*************************************
C*************************************************************************************

! PP  a carga de atualizao da presso externa lateral na ANLGM


PP = FPEL*PPU				! Parcela Presso Externa Lateral   0 < PP =< PPU


! PC  a carga de atualizao do carregamento de compresso na ANLGM


PC = 1.5*PCU				! Atualizao do carregamento para ANLGF
		

!===== Ttulo da Anlise =====


/TITLE,%Arq%-FPEL%FPEL% Ro%Ro% t%t% Lo%Lo% f_y%f_y% el_size%el_size% 

 
!===== Tipo do Elemento =====


ET,1,SHELL181           !Elemento da casca do perfil


sect,1,shell,,		!Atribuio da espessura Sections/Shell/Lay-up/Add/Edit	
secdata,t,1,0.0,5
secoffset, MID
seccontrol,,,, , , ,  


!===== Material - flambagem elastica =====


MP,EX,1,E              !Atribuio do mdulo de elasticidade do ao do perfil
MP,PRXY,1,v            !Atribuio do coeficiente de poisson do ao do perfil


!===== Criacao dos keypoints =====


K,1,0,0,0
K,2,Ro,0,0,
K,3,Ro,0,Lo,
K,4,0,0,Lo,


!===== Organizar a vista =====


/VIEW,1,1,1,1   
/ANG,1  
/REP,FAST



!===== Criacao da linha =====


L,2,3,             	! Traa a linha entre dois keypoints




!===== Extrusao da linha =====


FLST,2,1,4,ORDE,1   
FITEM,2,1   
FLST,8,2,3  
FITEM,8,1   
FITEM,8,4   
AROTAT,P51X, , , , , ,P51X, ,360, ,
 

!===== Posiciona o Workplane em Lo/2 =====


WPAVE,0,0,0
WPCSYS,-1,0
WPOFFS,0.0,0.0,Lo/2
ASBW,ALL


!===== Mesclar Linhas, reas, etc =====


ALLSEL,ALL
NUMMRG,ALL, , , ,LOH



!===== Discretizao da rea =====


ALLSEL,ALL		     ! Selects all entities with a single command.
MSHKEY,0
AESIZE,ALL,el_size	     ! Tamanho da malha
AMESH,ALL		     ! Efetuar a malha


C*************************************************************************************
C****************************APLICAO DO CARREGAMENTO********************************
C*************************************************************************************


! Aplicao da presso externa lateral para anlise esttica e de buckling 


NSEL,ALL

SF,ALL,PRES,-1,



! Atribuir o nmero de ns a uma varivel 


NSEL,ALL
NSEL,S,LOC,Z,0.0,0.0        	       ! Seleciona os ns em Z(0)
*GET,numnod1,NODE,0,COUNT	       ! Store the number of nodes and elements in the currently selected node

NSEL,ALL
NSEL,S,LOC,Z,Lo+001,Lo-0.001           ! Seleciona os ns em Z(Lo)
*GET,numnod2,NODE,0,COUNT	       ! Store the number of nodes and elements in the currently selected node



C*************************************************************************************
C****************************CONDIES DE CONTORNO**********************************
C*************************************************************************************

!===== Condies de Contorno nas extremidades =====


NSEL,ALL 				!seleciona todas as reas

NSEL,S,LOC,Z,0.0,0.0        		!seleciona os ns em Z(0)
NSEL,A,LOC,Z,Lo-0.001,Lo+0.001          !seleciona os ns em Z(Lo)


D,ALL,UX			        !aplicando restrio ao deslocamento na direo x
D,ALL,UY			        !aplicando restrio ao deslocamento na direo y
!D,ALL,ROTY			        !aplicando restrio ao giro em torno do eixo y
!D,ALL,ROTZ			        !aplicando restrio ao giro em torno do eixo z
!D,ALL,ROTX			        !aplicando restrio ao giro em torno do eixo x

!DLIST,ALL 			        ! List DOF constraints for all selected nodes



!===== Condies de Contorno no centro =====

NSEL,ALL 				!seleciona todas as reas

NSEL,S,LOC,Z,Lo/2-0.001,Lo/2+0.001      !seleciona os ns em Z(Lo/2)
D,ALL,UZ,0, , , , ,         		!restrio dos ns UZ




! Visualizar o tubo com os carregamentos aplicados 

ALLSEL,ALL		     ! Selects all entities with a single command.
/PSF,PRES,NORM,1,0,1
/PBC,ALL,,1 
/VIEW,1,1,1,1   
/ANG,1  
/REP,FAST



C*************************************************************************************
C********************************BUCKLING ANLISE*************************************
C*************************************************************************************


ALLSEL,ALL

/SOLU              ! Enter the solution mode

PSTRES,ON          ! Prestress can be accounted for - required during buckling analysis
            
ANTYPE,STATIC      ! Antes de fazer Buckling Anlise, precisa fazer uma anlise esttica

NLGEOM,OFF	   ! Desliga as grandes deformaes e o arc-length, redefine o tempo da anlise como 1 e apenas um substep, suficiente para a anlise linear
ARCLEN,OFF
TIME,1
NSUBST,1

/STATUS,SOLU
SOLVE
FINISH


/SOLU              !Enter the solution mode again to solve buckling


ANTYPE,BUCKLE      !Buckling analysis
BUCOPT,LANB,20      !Buckling options - subspace, 10 mode
SOLVE
FINISH


/SOLU		   !Re-enter solution mode to expand info - necessary

EXPASS,ON          !An expantion pass will be performed
MXPAND,20	   !Nmero de modos de instabilidade expandido nos resultados
SOLVE
FINISH


/POST1		   !Enter post-processor

SET,LIST	   !List eigenvalue solution - Time/Freq listing is the force required for buckling (in N for this case).
SET,FIRST	   !Read in data for the desired mode
PLDISP		   !Plots the deflected shape
FINISH



!==== Salvar o .txt da anlise de Buckling ====

/post1
/out,set_list,txt
set,list,first
/out,Tela_Arq_%Arq%,out,,APPEND

/RENAME,set_list,txt,,Arq %Arq% - Lista Buckling,TXT 	! Ex: /RENAME,A,,,B renames file A to B in the same directory.



!==== Salvar a carga de Buckling no arquivo .txt ====

SET,FIRST
*GET,buck_res,ACTIVE,,SET,TIME			! Salvar a carga de buckling na varivel buck_res
*CFOPEN,ARQ_BUCKLING,txt,,APPEND
*VWRITE,%Arq%,buck_res
(F4.0,1X,F15.10)				! F15.10 - 15 nmero total de algarismo 10  a quantidade de algarismo aps vrgula
*CFCLOS						! 1X  o espao vazio no arquivo .txt - no  necessrio atribuir algo no comando *VWRITE,....



C*************************************************************************************
C******************PRODUZIR A IMAGEM "MODOF" -  CARGA DE BUCKLING*********************
C*************************************************************************************


/POST1		   	!Enter post-processor

SET,LIST	   	!List eigenvalue solution - Time/Freq listing is the force required for buckling (in N for this case).
SET,,, ,,, ,MODOF       !Read in data for the desired mode
PLDISP		   	!Plots the deflected shape
FINISH


!==== Alterar o padrao de cores para impresso ====

/RGB,INDEX,100,100,100, 0   
/RGB,INDEX, 80, 80, 80,13   
/RGB,INDEX, 60, 60, 60,14   
/RGB,INDEX, 0, 0, 0,15  
/REPLOT 


!==== Plota o mximo deslocamento ====

/post1
plnsol,u,sum


!==== Organizar a vista - vista para contar as semiondas ====


! (i) vista isometrica

/REPLOT 
/VIEW,1,1,2,3   
/ANG,1  
/REP,FAST   
/AUTO,1 
/REP,FAST


!==== Comandos para salvar imagem com nome ====

*GET,flname,ACTIVE,,JOBNAM
/UI,COPY,SAVE,PNG,GRAPH,COLOR,NORM,PORTRAIT,
/RENAME,%flname%000,png,,Arq %Arq% - Buckling Iso-%MODOF%,PNG 	 !Ex: /RENAME,A,,,B renames file A to B in the same directory.


!==== (i) vista da secao transversal ====

/REPLOT 
/VIEW,1,,,1 
/ANG,1  
/REP,FAST   
/AUTO,1 
/REP,FAST


!==== Comandos para salvar imagem com nome ====

*GET,flname,ACTIVE,,JOBNAM
/UI,COPY,SAVE,PNG,GRAPH,COLOR,NORM,PORTRAIT,
/RENAME,%flname%000,png,,Arq %Arq% - Buckling Secao Transversal-%MODOF%,PNG 			!Ex: /RENAME,A,,,B renames file A to B in the same directory.





C****************************************************************************
C************************IMPERFEIES GEOMTRICAS****************************
C****************************************************************************


/NERR, 0, , , , 0 	 ! Limits the number of warning and error messages displayed.


/prep7                   !Enter the preprocessor


!====IMPERFEIO GEOMTRICA==== MainMenu-Modeling-Update Geom


DMX = 1.00000	                                	! Deslocamento mximo local do Ansys
FATglob=ImpG/DMX                                	! Fator de amplificao da amplitude global requerida                                               
UPGEOM,FATglob,1,MODOF,Arq_%Arq%,rst     		! Atualizao da geometria (Buckling File) "1"=step (no caso flambagem  1) MODOF=substep (varia com os 
							! modos de flambagem

/SOLU                     				! Start solution phase

!========================================================================
! ============== PRESSO EXTERNA LATERAL PARA 1 ANLGM ==================
!========================================================================


! (i) Aplicao do carregamento no costado - PP


NSEL,ALL					! Seleciona todos os ns

SFDELE,ALL,PRES					! Deleta os carregamentos em todos os ns
FDELE,ALL					! Deleta as foras em todos os ns

NSEL,ALL					! Seleciona todos os ns
SF,ALL,PRES,-PP,				! Carregamento atualizado (ATUALIZAR)


! Introduo da NLF do material

TB,BISO,1,1,2,  
TBDATA,,f_y,0.0001,,,,            			! No linearidade fsica, tenso X deformao 1/10000



!====OPES DE PROCESSAMENTO==== Solution/Analysis Options


RESCONTROL,DEFINE,ALL,1 			! Use Multi-Frame Restart for Last Load Step ESSA LINHA  IMPORTANTE PARA REINICIAR A SOLUES

ANTYPE,0                                        ! Anlise esttica (comando PSTRESS exige sua ativao)
NLGEOM,1                                        ! Ativa a no linearidade geomtrica
                          
!====Controls for database and results file writing====Solution/Load Step Opts/DB/Results File


OUTRES,ERASE                                 	 ! Controla os dados da soluo gravados no banco de dados
OUTRES,ALL,ALL                                     

!====Time and Time step options==== Solution/LoadStepOpts/TimeFrequenc/Time-Time Step

TIME,PP                                          	! Time at end of load step (editvel)
NSUBST,10,1000,10					! Especifica o nmero de substeps a serem realizadas nesta etapa de carregamento,nmero de mximo e mnimo de substeps. 					  	
							! If automatic time stepping is used (AUTOTS), NSBSTP defines the size of the first substep and
							! the program automatically determines nmero de mximo e mnimo de substeps default based on the physics of the model.

!AUTOTS,OFF
!AUTOTS,ON						! Specifies whether to use automatic time stepping or load stepping
							! ON - Use automatic time stepping (default)
							! OFF - Do not use automatic time stepping.

!===Soluo====							
                                            
ALLSEL,ALL                                          
SOLVE
FINISH


!========================================================================
! =============== CARGA DE COMPRESSO PARA 2 ANLGM =====================
!========================================================================

FINISH


/SOLU                     			! Start solution phase


ANTYPE,,RESTART,1,10,CONTINUE        		!LINHA QUE REINICIA A ANLISE

ALLSEL,ALL 


NSEL,ALL					! Seleciona todos os ns

SFDELE,ALL,PRES					! Deleta os carregamentos em todos os ns
FDELE,ALL					! Deleta as foras em todos os ns


! (ii) Aplicao do carregamento nas extremidades PC


LSEL,S,,,7
LSEL,A,,,5
LSEL,A,,,9
LSEL,A,,,11
NSLL,S,1


F,ALL,FZ,PC/numnod1

LSEL,S,,,8
LSEL,A,,,6
LSEL,A,,,10
LSEL,A,,,12
NSLL,S,1


F,ALL,FZ,-PC/numnod2


!====Time and Time step options==== Solution/LoadStepOpts/TimeFrequenc/Time-Time Step

!ANTYPE,0                                        	! Anlise esttica (comando PSTRESS exige sua ativao)
!NLGEOM,1                                         	! Ativa a no linearidade geomtrica

PRED,ON,,ON            					! Activates a predictor in a nonlinear analysis

TIME,200                                          	! Time at end of load step (editvel)
NSUBST,300,1000,10 			
!stabilize,constant,energy,0.01 			! Use energy method with constant option

NEQIT, 40

AUTOTS,ON
                                          
ALLSEL,ALL                                          


SOLVE
FINISH

